package thinkingJava.chapter14;

import java.util.ArrayList;

public class Staff extends ArrayList<Position> {
	public void add(String title , Person2 person) {
		add(new Position(title, person));
	}
	public void add(String... titles) {
		for (String title : titles) {
			add(new Position(title));
		}
	}
	public Staff(String... titles) {
		add(titles);
	}
	public boolean positionAvailable(String title) {
		for (Position position : this) {
			if (position.getTitle().equals(title) && position.getPerson() == Person2.NULL) {
				return true;
			}
		}
		return false;
	}
	public void fillPosition(String title , Person2 hire) {
		for (Position position : this) {
			if (position.getTitle().equals(title) && position.getPerson() == Person2.NULL) {
				position.setPerson(hire);
				return;
			}
		}
		throw new RuntimeException(" position " + title + " not available!");
	}
	public static void main(String[] args) {
		Staff staff = new Staff("President","CTO",
				"Markeing Manager", "Product Manager",
				"Project Lead", "Software Engineer",
				"Software Engineer", "Software Engineer",
				"Software Engineer", "Test engineer",
				"Technical Writer");
		staff.fillPosition("President", new Person2("Me", "Last", "The Top, Lonely At"));
		staff.fillPosition("Project Lead", new Person2("Janet", "Planner", "the Blurbs"));
		staff.fillPosition("Software Engineer", new Person2("Bob", "coder", "the Blight City"));
		System.out.println(staff);
	}
}
